package cn.wolfcode.wolf2w.business.controller;

import cn.wolfcode.wolf2w.business.api.domain.StrategyContent;
import cn.wolfcode.wolf2w.business.service.IStrategyContentService;
import cn.wolfcode.wolf2w.common.core.constant.SecurityConstants;
import cn.wolfcode.wolf2w.common.core.domain.R;
import cn.wolfcode.wolf2w.common.security.annotation.InnerAuth;
import cn.wolfcode.wolf2w.business.api.domain.Strategy;
import cn.wolfcode.wolf2w.business.query.StrategyQuery;
import cn.wolfcode.wolf2w.business.service.IStrategyService;
import cn.wolfcode.wolf2w.common.security.annotation.RequiresLogin;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.wolfcode.wolf2w.api.domain.StrategyCatalog;

import javax.naming.Name;
import javax.print.attribute.standard.MediaSize;
import java.util.List;
import java.util.Map;

/**
 * 攻略 Controller
 *
 * @author 沙琪玛
 * @date 2024-11-01
 */
@Api(value = "攻略接口", description = "攻略pc接口控制器,定义了攻略相关的接口资源")
@RestController
@ApiResponses({
        @ApiResponse(code = 200, message = "成功"),
        @ApiResponse(code = 400, message = "参数错误"),
        @ApiResponse(code = 401, message = "未登录"),
        @ApiResponse(code = 403, message = "无权限"),
        @ApiResponse(code = 404, message = "找不到该接口"),
        @ApiResponse(code = 500, message = "服务器异常"),
        @ApiResponse(code = 501, message = "业务异常")
}
)
@RequestMapping("strategies")
public class StrategyController {
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private IStrategyContentService strategyContentService;

    /**
     * 攻略详情
     */
    @ApiOperation(value = "攻略详情", notes = "根据攻略id查询攻略详情接口")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "id", value = "攻略id", defaultValue = "Integer", example = "4", required = true)
    )

    @GetMapping("/detail/{id}")
    public R<Strategy> detail(@PathVariable Long id) {
        Strategy strategy = strategyService.getById(id);
        StrategyContent content = strategyContentService.getById(id);
        strategy.setContent(content);
        return R.ok(strategy);
    }

    /**
     * 攻略 列表
     */
    @ApiOperation(value = "攻略列表", notes = "根据攻略id查询攻略列表接口")
    @GetMapping("/query")
    public R<IPage<Strategy>> query(StrategyQuery qo) {
        IPage<Strategy> page = strategyService.queryPage(qo);
        return R.ok(page);
    }

    @GetMapping("/catalogList")
    public R<List<StrategyCatalog>> catalogList(Long destId) {
        List<StrategyCatalog> list = strategyService.queryCatalogList(destId);
        return R.ok(list);
    }

    @GetMapping("/viewnnumTop3")
    public R<List<Strategy>> viewnnumTop3(Long destId) {
        List<Strategy> list = strategyService.getViewnnumTop3(destId);
        return R.ok(list);
    }

    @PostMapping("/viewnumIncr")
    public R<?> viewnumIncr(Long sid) {
        Map<String, Object> map = strategyService.viewnumIncr(sid);
        return R.ok(map);
    }

    @PostMapping("/replynumIncr")
    public R<?> replynumIncr(Long sid) {
        Map<String, Object> map = strategyService.replynumIncr(sid);
        return R.ok(map);
    }

    @GetMapping("/isUserFavor")
    public R<?> isUserFavor(Long sid, Long uid) {
        boolean b = strategyService.isUserFavor(sid, uid);
        return R.ok(b);
    }

    @PostMapping("/thumbsup")
    public R<?> thumbsup(Long sid) {
        Map<String, Object> map = strategyService.thumbsup(sid);
        return R.ok(map);
    }

    @RequiresLogin
    @PostMapping("/favor")
    public R<?> favor(Long sid) {
        Map<String, Object> map = strategyService.favor(sid);
        return R.ok(map);
    }


    /*****************************************对外暴露Fegin接口**********************************************/
    /**
     * Feign 接口
     */
    @GetMapping("/feign/list")
    public R<List<Strategy>> feignList() {
        return R.ok(strategyService.list());
    }

    @InnerAuth
    @GetMapping("/feign/{id}")
    public R<Strategy> feignGet(@PathVariable Long id) {
        return R.ok(strategyService.getById(id));
    }

    @PostMapping("/feign/statisHashPersistence")
    public R<?> statisHashPersistence() {
        strategyService.statisHashPersistence();
        return R.ok();
    }
}
